<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>宏观经济多维图表分析（2024Q2–2025Q3）</title>
  <!-- 使用多个CDN源确保ECharts库加载 -->
  <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
  <style>
    body { font-family: "Microsoft YaHei", sans-serif; margin: 0; padding: 20px; background: #f9f9f9; }
    .chart-container { width: 95%; max-width: 1200px; margin: 20px auto; background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 15px; }
    h2 { text-align: center; color: #333; margin-top: 0; }
    .loading { text-align: center; padding: 50px; color: #666; }
    .error { text-align: center; padding: 50px; color: #d32f2f; }
  </style>
</head>
<body>

<h1 style="text-align:center; color:#2c3e50;">宏观经济多维图表分析（2024Q2 – 2025Q3）</h1>

<!-- 加载提示 -->
<div id="loading" class="loading">正在加载图表...</div>

<!-- 图表1：GDP 当季值趋势 -->
<div class="chart-container">
  <h2>1. GDP 当季值变化趋势（亿元）</h2>
  <div id="chart1" style="height:400px;"></div>
</div>

<!-- 图表2：GDP 累计 vs 当季（双轴） -->
<div class="chart-container">
  <h2>2. GDP 累计值与当季值对比</h2>
  <div id="chart2" style="height:400px;"></div>
</div>

<!-- 图表3：2025Q3 产业结构环形图 -->
<div class="chart-container">
  <h2>3. 2025年第三季度产业结构占比</h2>
  <div id="chart3" style="height:400px;"></div>
</div>

<!-- 图表4：三大产业累计值堆叠面积图 -->
<div class="chart-container">
  <h2>4. 三大产业累计增加值（堆叠面积图）</h2>
  <div id="chart4" style="height:400px;"></div>
</div>

<!-- 图表5：2025Q3 各产业当季值横向条形图 -->
<div class="chart-container">
  <h2>5. 2025Q3 各产业当季增加值对比</h2>
  <div id="chart5" style="height:300px;"></div>
</div>

<!-- 图表6：环比增长率雷达图 -->
<div class="chart-container">
  <h2>6. 2025Q3 相比 2025Q2 各产业环比增长率（%）</h2>
  <div id="chart6" style="height:400px;"></div>
</div>

<!-- 图表7：热力图 -->
<div class="chart-container">
  <h2>7. 各产业当季增加值热力图</h2>
  <div id="chart7" style="height:350px;"></div>
</div>

<!-- 图表8：散点图 -->
<div class="chart-container">
  <h2>8. GDP 与第三产业相关性</h2>
  <div id="chart8" style="height:400px;"></div>
</div>

<script>
// 确保DOM加载完成后再执行
document.addEventListener('DOMContentLoaded', function() {
  // 检查ECharts是否加载成功
  if (typeof echarts === 'undefined') {
    document.getElementById('loading').innerHTML = '<div class="error">ECharts库加载失败，请检查网络连接或CDN地址</div>';
    return;
  }

  // 隐藏加载提示
  document.getElementById('loading').style.display = 'none';

  // 全局数据
  const quarters = ['2024Q2', '2024Q3', '2024Q4', '2025Q1', '2025Q2', '2025Q3'];
  const data = {
    gdp_current: [328837.6, 349238.3, 373726.2, 318758.0, 341777.8, 354500.2],
    gdp_cumulative: [597996.9, 947235.2, 1320961.4, 318758.0, 660535.8, 1015036.0],
    primary_current: [19459.0, 22530.0, 25100.0, 18700.0, 19459.0, 26889.0],
    secondary_current: [127147.3, 132500.0, 138000.0, 120000.0, 127147.3, 124969.8],
    tertiary_current: [195171.6, 204208.3, 210626.2, 180058.0, 195171.6, 202641.4],
    primary_cum: [38918.0, 61448.0, 86548.0, 18700.0, 38159.0, 65048.0],
    secondary_cum: [254294.6, 386794.6, 524794.6, 120000.0, 247147.3, 372117.1],
    tertiary_cum: [304784.3, 509092.6, 719718.8, 180058.0, 375229.6, 577871.0]
  };

  // 工具函数：计算环比增长率
  function calcGrowth(prev, curr) {
    return ((curr - prev) / prev * 100).toFixed(2);
  }

  // === 图表1：GDP 当季值折线图 ===
  const chart1 = echarts.init(document.getElementById('chart1'));
  chart1.setOption({
    tooltip: { trigger: 'axis' },
    xAxis: { type: 'category', data: quarters },
    yAxis: { type: 'value', name: '亿元' },
    series: [{
      name: 'GDP 当季值',
      type: 'line',
      smooth: true,
      symbol: 'circle',
      lineStyle: { width: 3 },
      data: data.gdp_current,
      markPoint: { data: [{ type: 'max', name: '最大值' }, { type: 'min', name: '最小值' }] }
    }]
  });

  // === 图表2：双轴图（柱+线）===
  const chart2 = echarts.init(document.getElementById('chart2'));
  chart2.setOption({
    tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } },
    legend: { data: ['累计值', '当季值'] },
    xAxis: { type: 'category', data: quarters },
    yAxis: [
      { type: 'value', name: '累计值（亿元）', position: 'left' },
      { type: 'value', name: '当季值（亿元）', position: 'right', min: 300000, max: 380000 }
    ],
    series: [
      {
        name: '累计值',
        type: 'bar',
        data: data.gdp_cumulative,
        itemStyle: { color: '#5470c6' }
      },
      {
        name: '当季值',
        type: 'line',
        yAxisIndex: 1,
        data: data.gdp_current,
        symbol: 'circle',
        itemStyle: { color: '#91cc75' }
      }
    ]
  });

  // === 图表3：环形图（2025Q3 结构）===
  const q3_idx = 1; // 2025Q3 是第6个（索引5）
  const pieData = [
    { name: '第一产业', value: data.primary_current[q3_idx] },
    { name: '第二产业', value: data.secondary_current[q3_idx] },
    { name: '第三产业', value: data.tertiary_current[q3_idx] }
  ];
  const chart3 = echarts.init(document.getElementById('chart3'));
  chart3.setOption({
    tooltip: { trigger: 'item' },
    legend: { orient: 'vertical', left: 'left' },
    series: [{
      name: '产业结构',
      type: 'pie',
      radius: ['20%', '70%'],
      data: pieData,
      label: { formatter: '{b}: {d}%' }
    }]
  });

  // === 图表4：堆叠面积图（用 line + areaStyle）===
  const chart4 = echarts.init(document.getElementById('chart4'));
  chart4.setOption({
    tooltip: { trigger: 'axis' },
    legend: { data: ['第一产业', '第二产业', '第三产业'] },
    xAxis: { type: 'category', data: quarters },
    yAxis: { type: 'value', name: '亿元' },
    series: [
      {
        name: '第一产业',
        type: 'line',
        stack: '总量',
        areaStyle: {},
        data: data.primary_cum
      },
      {
        name: '第二产业',
        type: 'line',
        stack: '总量',
        areaStyle: {},
        data: data.secondary_cum
      },
      {
        name: '第三产业',
        type: 'line',
        stack: '总量',
        areaStyle: {},
        data: data.tertiary_cum
      }
    ]
  });

  // === 图表5：横向条形图（2025Q3）===
  const barData = [
    { name: '第一产业', value: data.primary_current[q3_idx] },
    { name: '第二产业', value: data.secondary_current[q3_idx] },
    { name: '第三产业', value: data.tertiary_current[q3_idx] }
  ].sort((a, b) => a.value - b.value); // 升序

  const chart5 = echarts.init(document.getElementById('chart5'));
  chart5.setOption({
    tooltip: { trigger: 'axis' },
    xAxis: { type: 'value', name: '亿元' },
    yAxis: {
      type: 'category',
      data: barData.map(d => d.name)
    },
    series: [{
      type: 'bar',
      data: barData.map(d => d.value),
      label: { show: true, position: 'right', formatter: '{c}' }
    }]
  });

  // === 图表6：雷达图（环比增长率）===
  const q2_idx = 4;
  const growth = [
    parseFloat(calcGrowth(data.primary_current[q2_idx], data.primary_current[q3_idx])),
    parseFloat(calcGrowth(data.secondary_current[q2_idx], data.secondary_current[q3_idx])),
    parseFloat(calcGrowth(data.tertiary_current[q2_idx], data.tertiary_current[q3_idx]))
  ];

  const chart6 = echarts.init(document.getElementById('chart6'));
  chart6.setOption({
    tooltip: {},
    radar: {
      indicator: [
        { name: '第一产业', max: 50 },
        { name: '第二产业', max: 10 },
        { name: '第三产业', max: 10 }
      ]
    },
    series: [{
      type: 'radar',
      data: [{ name: '环比增长率（%）', value: growth }]
    }]
  });

  // === 图表7：热力图 ===
  const industries = ['第一产业', '第二产业', '第三产业'];
  const currentMatrix = [
    data.primary_current,
    data.secondary_current,
    data.tertiary_current
  ];

  const heatmapData = [];
  currentMatrix.forEach((row, i) => {
    row.forEach((val, j) => {
      heatmapData.push([j, i, Math.round(val)]);
    });
  });

  const chart7 = echarts.init(document.getElementById('chart7'));
  chart7.setOption({
    tooltip: { position: 'top' },
    grid: { height: '70%', y: '10%' },
    xAxis: {
      type: 'category',
      data: quarters,
      splitArea: { show: true }
    },
    yAxis: {
      type: 'category',
      data: industries,
      splitArea: { show: true }
    },
    visualMap: {
      min: 18000,
      max: 210000,
      calculable: true,
      orient: 'horizontal',
      left: 'center',
      bottom: '0%'
    },
    series: [{
      type: 'heatmap',
      data: heatmapData,
      label: { show: true }
    }]
  });

  // === 图表8：散点图（GDP vs 第三产业）===
  const scatterData = data.gdp_current.map((gdp, i) => [gdp, data.tertiary_current[i]]);

  const chart8 = echarts.init(document.getElementById('chart8'));
  chart8.setOption({
    tooltip: { trigger: 'item' },
    xAxis: { type: 'value', name: 'GDP 当季值（亿元）' },
    yAxis: { type: 'value', name: '第三产业（亿元）' },
    series: [{
      type: 'scatter',
      data: scatterData,
      symbolSize: function (val) { return 60; },
      itemStyle: { color: 'purple' }
    }]
  });

  // 自适应窗口大小
  window.addEventListener('resize', () => {
    chart1.resize();
    chart2.resize();
    chart3.resize();
    chart4.resize();
    chart5.resize();
    chart6.resize();
    chart7.resize();
    chart8.resize();
  });
});
</script>

</body>
</html>